import request from "@/utils/request.ts";
import type {
  CategoryList,
  AttrListData,
  AttrListItem,
} from "./models/getCategoryType.ts";

/**
 * 一级分类列表数据
 * @returns CategoryList
 */
export const reqGetCategory1List = () => {
  return request.get<any, CategoryList>("/admin/product/getCategory1");
};

/**
 * 二级分类数据
 * @param category1Id  通过一级id获取二级数据
 * @returns CategoryList
 */
export const reqGetCategory2List = (category1Id: number) => {
  return request.get<any, CategoryList>(
    `/admin/product/getCategory2/${category1Id}`
  );
};

/**
 * 三级数据
 * @param category2Id 二级id
 * @returns CategoryList
 */
export const reqGetCategory3List = (category2Id: number) => {
  return request.get<any, CategoryList>(
    `/admin/product/getCategory3/${category2Id}`
  );
};

/**
 * 获取属性列表
 * @param category1Id
 * @param category2Id
 * @param category3Id
 * @returns AttrListData
 */
export const reqGetAttrInfoList = (
  category1Id: number,
  category2Id: number,
  category3Id: number
) => {
  return request.get<any, AttrListData>(
    `/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`
  );
};

/**
 * 添加和修改请求
 * @param attr
 * @returns null
 */
export const reqAddOrEditAttr = (attr: AttrListItem) => {
  return request.post<any, null>(`/admin/product/saveAttrInfo`, attr);
};

/**
 * 删除操作
 * @param attrId 
 * @returns null
 */
export const reqDeleteAttr = (attrId: number) => {
  return request.delete<any, null>(`/admin/product/deleteAttr/${attrId}`);
};
